/*
 * 
 * Created on Jul 11, 2005
 */
package remato.client.model;

import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.views.properties.PropertyDescriptor;

/**
 *
 * @author plhe - Petter L. H. Eide <petter@eide.biz>
 * @version $Id: AbstractPropertySpesification.java,v 1.1 2006-01-23 19:58:37 petterei Exp $
 */
public abstract class AbstractPropertySpesification implements Comparable<AbstractPropertySpesification> {

	/**
	 * TODO: use?
	 */
	public abstract Long getIdentifier();

	public abstract String getLabel();
	
	public abstract void setLabel(String label);
	
	public abstract String getDescription();
	
	public abstract void setDescription(String description);
	
	/**
	 * Used for sorting.
	 */
	public abstract int getPosition() ;

	public abstract void setPosition(int position) ;

	public abstract PropertyType getPropertyType() ;
	
	public abstract String getDefaultValue();
	
	public abstract void setDefaultValue(String value);

	public boolean hasDefaultValue() {
		boolean defaultValue = false;
		if (this.getDefaultValue() != null) {
			defaultValue = true;
		}
		return defaultValue;
	}

	/**
	 * Compares this object with the specified object for order. Returns a
	 * negative integer, zero, or a positive integer as this object is less
	 * than, equal to, or greater than the specified object.
	 * 
	 * @see java.lang.Comparable#compareTo(Object)
	 */
	public int compareTo(AbstractPropertySpesification o) {
		int i = 0;
		if (this.getPosition() < o.getPosition()) {
			i = -1;
		} else if (this.getPosition() > o.getPosition()) {
			i = 1;
		}
		return i;
	}

	public PropertyDescriptor getDescriptor() {
		PropertyDescriptor descriptor = getPropertyType().getDescriptor(this, getLabel()); 
		descriptor.setDescription(getDescription());
		return descriptor;
	}

	public CellEditor getCellEditor(Composite parent) {
		CellEditor editor = getPropertyType().getCellEditor(parent);
		return editor;
	}

}
